package com.ny.demo;


    // 定义宠物基类
    class Pet {
        private String name;
        private int age;

        public Pet(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public int getAge() {
            return age;
        }

        public String makeSound() {
            return "汪汪汪";
        }
    }

    // 定义狗类，继承自Pet类
    class Dog extends Pet {
        public Dog(String name, int age) {
            super(name, age);
        }

        @Override
        public String makeSound() {
            return "汪汪汪";
        }
    }

    // 定义猫类，继承自Pet类
    class Cat extends Pet {
        public Cat(String name, int age) {
            super(name, age);
        }

        @Override
        public String makeSound() {
            return "喵喵喵";
        }
    }

    public class animal {
        public static void main(String[] args) {
            // 创建一些宠物实例
            Dog dog1 = new Dog("小黄", 3);
            Cat cat1 = new Cat("花猫", 2);

            // 测试宠物发出声音
            System.out.println(dog1.getName() + " is " + dog1.getAge() + " years old and says " + dog1.makeSound());
            System.out.println(cat1.getName() + " is " + cat1.getAge() + " years old and says " + cat1.makeSound());
        }
    }

